    //
    //  LiveSizeConfig.m
    //  ParentsCommunity
    //
    //  Created by caiyonghao on 16/10/19.
    //  Copyright © 2016年 XES. All rights reserved.
    //
#import "LiveSizeConfig.h"
#import "UIScreen+WXUtility.h"

static CGFloat kVideoRatioValue = 9 / 16.0f;

@implementation LiveSizeConfig

+ (CGFloat)screenWidth {

    return MAX(kCurrentScreenWidth, kCurrentScreenHeight);
}

+ (CGFloat)screenHeight {

    return MIN(kCurrentScreenWidth, kCurrentScreenHeight);
}

+ (CGFloat)getLiveVideoAspectRatio {

    return livePPTHeight/(livePPTWidth + liveHeadAreaWidth);

}

+ (CGFloat)getLivePPTAspectRatio {

    return  livePPTWidth/livePPTHeight;
}

+ (CGFloat)getLiveVideoAndPPTWdithRatio {

    return livePPTWidth/(livePPTWidth+liveHeadAreaWidth);

}

+ (CGFloat)getLiveVideoAndHeadAreaWidthRatio {

    return liveHeadAreaWidth/(livePPTWidth+liveHeadAreaWidth);

}

+ (CGFloat)getLiveVideoAndChatHeightRatio {

    return (1-liveHeadAreaHeight/livePPTHeight);
}

+ (CGFloat)getPPTLeftMargin {
    return [LiveSizeConfig getHorizontalSpace];
}

+ (CGFloat)getPPTRightMargin{
    return [LiveSizeConfig getChatViewWidth]+[LiveSizeConfig getHorizontalSpace];
}

+ (CGFloat)getPPTBottomMargin{
    return (([LiveSizeConfig screenHeight]-[LiveSizeConfig getPPTHeight])*0.5);
}

    /*!
     * @brief 是否是iphoneX
     */
+ (BOOL)isIphoneX {

    CGFloat width = [self screenWidth];
    CGFloat height = [self screenHeight];
    BOOL isIphoneX = (ceil(width)  == 812) && (ceil(height) == 375);
    BOOL isIphoneXMAXorXR = (ceil(width)  == 896) && (ceil(height) == 414);
    return (isIphoneX || isIphoneXMAXorXR);
}

    /*!
     * @brief 水平方向的间距
     */
+ (CGFloat)getHorizontalSpace {

    CGFloat width = [self screenWidth];
    CGFloat height = [self screenHeight];
    CGFloat videoHeight = width *kVideoRatioValue;

    if (videoHeight > height) {

        CGFloat videoWidth = height / kVideoRatioValue;
        return  (width - videoWidth) / 2;
    }
    return  0;
}

    /*!
     * @brief 垂直方向间距
     */
+ (CGFloat)getVerticalSpace {

    CGFloat width = [self screenWidth];
    CGFloat height = [self screenHeight];
    CGFloat videoHeight = width *kVideoRatioValue;

    if (videoHeight < height) {

        return (height - videoHeight) / 2;
    }
    return 0;
}

    /*!
     * @brief 聊天区的宽度
     */
+ (CGFloat)getChatViewWidth {

    CGFloat width = [self screenWidth];
    CGFloat height = [self screenHeight];
    CGFloat videoHeight = width *kVideoRatioValue;
    if (videoHeight > height) {

        CGFloat videoWidth = height / kVideoRatioValue;
        return  videoWidth * [self getLiveVideoAndHeadAreaWidthRatio];
    }

    return width * [self getLiveVideoAndHeadAreaWidthRatio];
}

    /*!
     * @brief 聊天区的高度
     */
+ (CGFloat)getChatViewHeight {

    return [self getPPTHeight] * [self getLiveVideoAndChatHeightRatio];
}

    /*!
     * @brief PPT区域宽度
     */
+ (CGFloat)getPPTWidth {

    CGFloat width = [self screenWidth];
    CGFloat height = [self screenHeight];
    CGFloat videoHeight = width *kVideoRatioValue;
    if (videoHeight > height) {

        CGFloat videoWidth = height / kVideoRatioValue;
        return  videoWidth * [self getLiveVideoAndPPTWdithRatio];
    }

    return width * [self getLiveVideoAndPPTWdithRatio];
}

    /*!
     * @brief PPT区域高度
     */
+ (CGFloat)getPPTHeight {

    CGFloat height = [self screenHeight];
    return height - 2 * [self getVerticalSpace];
}

/*!
 * @brief 视频区域宽度
 */
+ (CGFloat)getVideoWidth
{
    return [self getPPTWidth] + [self getChatViewWidth];
}

/*!
 * @brief 视频区域高度
 */
+ (CGFloat)getVideoHeight
{
    return [self getPPTHeight];

}
@end

